<?
require("admin-header.php");

if (!isset($_REQUEST['cid'])){
	echo "No contest id!<br>";
	require("../oj-footer.php");
	exit(0);
}else $cid=intval($_REQUEST['cid']);

if (isset($_POST['user_list'])){
	// delete all the old ones;
	$sql="delete from `privilege` where `rightstr`='c$cid'";
//	echo $sql."<br>";
	mysql_query($sql) or die(mysql_error());
	// insert all the new ones;
	$teams=split("[\t\r\n ]+",$_POST['user_list']);
	$sql2="";
	foreach($teams as $team){
		if ($team=="") continue;
		if ($sql2=="") $sql2=$sql2."('$team','c$cid','N')";
		else $sql2=$sql2.",('$team','c$cid','N')";
	}
	if ($sql2!=""){
		$sql2="insert into `privilege` values ".$sql2;
//		echo $sql2."<br>";
		mysql_query($sql2);
	}
}

echo "<title>Team List for $cid</title>";
echo "<center><h2>Team List for $cid</h2></center>";
$sql="select `user_id` from `privilege` where `rightstr`='c$cid'";
$value="";
$res=mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_array($res)){
$value=$value.$row[0]."&#13;&#10;";
}
mysql_free_result($res);
echo "<h2>User List For Private Contest $cid</h2>";
echo "<form method='post' action="
.$_SERVER['PHP_SELF'].
"><textarea rows=20 cols=80 name=user_list>$value</textarea><br><input type=submit value=submit><input name=cid type=hidden value=$cid></form>";
require("../oj-footer.php");
?>
